﻿#region Using directives
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Ladenius.TheTVDB.Entities;
#endregion

namespace Ladenius.TheTVDB.Browser {
    public partial class Browse : System.Web.UI.Page {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e) {

            TheTVDBManager manager = new TheTVDBManager();

            // Retrieve language
            Language language = manager.GetLanguageByAbbreviation("en");

            // Retrieve a mirror for series banners.
            Mirror mirrorBanners = manager.GetMirror_SeriesBanners();

            // Find a series by name a display
            List<Series> foundSeries = manager.FindSeries("Star Trek");
            foreach (Series series in foundSeries)
                Page.Controls.Add(new LiteralControl(series.Name + "<br />"));

            // Find a specific series by ID and display name
            Series startrek = manager.GetSeriesByID(77526, language);
            Page.Controls.Add(new LiteralControl("<HR><h1>" + startrek.Name + "</h1>"));
            Page.Controls.Add(new LiteralControl("<img src=\"" + mirrorBanners.MirrorPath + "/banners/" + startrek.Banner + "\" />"));

            // Get all seasons and episodes and display
            Dictionary<int, List<Episode>> seasons = manager.GetSeasonsBySeriesID(startrek.ID, language);
            foreach (int i in seasons.Keys) {
                Page.Controls.Add(new LiteralControl("<h2>Season " + i + "</h2>"));
                foreach (Episode episode in seasons[i]) {
                    Page.Controls.Add(new LiteralControl(episode.Number + ". " + episode.Name + "<br />"));
                }
            }

        }
    }
}
